#include <iostream>
using namespace std;
int t, n, m;
string a, b, c;
int main(){
	cin >> t;
	while(t--){
		cin >> n >> a >> m >> b >> c;
		for (int i = 0; i < m; i++){
			if (c[i] == 'D'){
				a.push_back(b[i]);
			}
			else{
				a.insert(0, 1, b[i]);
			}
		}
		cout << a << endl;
		
	}
	return 0;
} 
